package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.nga.main.NgaApi
import com.gin.nga.response.forum.BlockedSubForum
import java.lang.ref.WeakReference

/**
 * 子版面屏蔽数据提供者，暂时弃用，可以直接通过状态判断选中
 * @property dir String
 */
class BlockSubForumProvider private constructor():AbstractCachedDataProvider<Long,List<BlockedSubForum>,List<Long>>(
    javaType = TYPE_FACTORY.constructCollectionLikeType(List::class.java, Long::class.java)
) {
    override val dir: String = "BLOCK_SUB_FORUM"

    override fun transform(rawData: List<BlockedSubForum>) = rawData.mapNotNull { it.blockTopicId }.flatten()

    override fun requestMethod(ngaApi: NgaApi, params: Long?) = ngaApi.forumApi.blockSubForumList(params!!)

    override fun obtainRelativePath(userId: Long, params: Long?) = "${userId}_${params}.json"

    companion object {
        private var instance: WeakReference<BlockSubForumProvider> = WeakReference(BlockSubForumProvider())
        fun getInstance(): BlockSubForumProvider = instance.get() ?: BlockSubForumProvider().also { instance = WeakReference(it) }
    }
}